import time
from selenium import webdriver
from selenium.webdriver import ActionChains, Keys
from selenium.webdriver.common.by import By

# 创建驱动对象
driver = webdriver.Edge()
# 打开网页
driver.get("file:///D:/pagetest/注册A.html")
time.sleep(3)

# 当下拉框是select标签，我们就用select对象来处理

# 先获取 下拉框元素对象
# ele = driver.find_element(By.CSS_SELECTOR, '#selectA')

# # 根据 元素对象 创建一个选择对象
# s = Select(ele)

# # 通过索引的方式来选择 索引从0开始
# s.select_by_index(1)

# time.sleep(3)
# # 通过value值的方式来选择
# s.select_by_value('gz')

# time.sleep(3)
# # 通过文本来选择
# s.select_by_visible_text('深圳')




# 关闭网页

# 非select标签处理
# 当下拉框不是select标签，我们可以通过ActionChains类，用鼠标点击和键盘操作处理
ele = driver.find_element(By.CSS_SELECTOR, '#selectA')
action = ActionChains(driver)
action.click(ele)
action.perform()

time.sleep(3)
action.send_keys(Keys.DOWN)
action.perform()

time.sleep(3)
action.send_keys(Keys.DOWN)
action.perform()

time.sleep(3)
action.send_keys(Keys.ENTER)
action.perform()

time.sleep(5)
driver.quit()

# action.send_keys(Keys.DOWN)



time.sleep(123)